package by.yakusekmaxim.bookgid.dataaccess.impl;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;

import org.springframework.stereotype.Repository;

import by.yakusekmaxim.bookgid.dataaccess.GenreDao;
import by.yakusekmaxim.bookgid.datamodel.Genre;

@Repository
public class GenreDaoImpl extends AbstractDaoImpl<Long, Genre> implements GenreDao {

    protected GenreDaoImpl() {
        super(Genre.class);
    }
    
    @Override
    public Long getCount() {
        CriteriaBuilder cBuilder = getEm().getCriteriaBuilder();

        CriteriaQuery<Long> criteria = cBuilder.createQuery(Long.class);
        Root<Genre> root = criteria.from(Genre.class);

        criteria.select(cBuilder.count(root));

        TypedQuery<Long> query = getEm().createQuery(criteria);
        return query.getSingleResult();
    }
}
